﻿function login(form, win) {
    var username = form.username.value;
    var password = form.password.value;
    var captcha = form.captcha.value;
    if (username.isEmpty()) {
        form.username.focus();
        $(".login-message").html('请输入您的帐号！');
        setTimeout(function () { $(".login-message").empty(); }, 3000);
        return false;
    }
    else if (password.isEmpty()) {
        form.password.focus();
        $(".login-message").html('请输入您的密码！');
        setTimeout(function () { $(".login-message").empty(); }, 3000);
        return false;
    }
    else if (captcha.isEmpty()) {
        form.captcha.focus();
        $(".login-message").html('请输入验证码！');
        setTimeout(function () { $(".login-message").empty(); }, 3000);
        return false;
    }
    else {
        var param = $(form).serialize();
        $.postJSON(form.action, param, function (result) {
            if (result.Status == true) {
                win.Sk.CurrentUser.IsAuthenticated = true;
                win.Sk.CurrentUser.NickName = result.Data;
                if (result.Extra != null && result.Extra != "") {
                    win.location = result.Extra;
                }
                else {
                    win.top.location.reload();
                }
            } else {
                $(".login-message").html(result.Message);
                setTimeout(function () { $(".login-message").empty(); }, 3000);
            }
        });
    }
    return false;
}